package com.li.proxy.cglib;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import java.lang.reflect.Method;

public class TimerMethodInterceptor implements MethodInterceptor {

    @Override
    public Object intercept(Object target, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        //前面增强
        long begin = System.currentTimeMillis();

        // 怎么调用目标对象的目标方法呢？
        Object retValue = methodProxy.invokeSuper(target, objects);

        //后面增强
        long end = System.currentTimeMillis();

        System.out.println("耗时：" + (end - begin));

        //有返回值记得返回目标方法的返回值
        return retValue;
    }
}
